<template>
  <el-dialog v-model="dialogFormVisible" :title="title" width="800px">
    <zFrom
      ref="zfrom"
      label-width="140px"
      :nowdata="formdata"
      :nowinputs="frominputs"
      @change="change"
    />
    <template #footer>
      <div class="dialog-footer">
        <el-button :loading="loading" type="primary" @click="save">
          {{ $z.$t('确定') }}
        </el-button>
        <el-button @click="close">{{ $z.$t('取消') }}</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
  import zFrom from '../zFrom/zFrom'
  export default {
    components: {
      zFrom,
    },
    data() {
      return {
        title: 'Excel导入',
        dialogFormVisible: false,
        formdata: {},
        frominputs: [
          {
            label: '桩号名称',
            value: 'gtelmc',
            defaultValue: '桩号',
          },
          {
            label: '选择Exel',
            value: 'excel',
            type: 'excel',
            defaultValue: '',
            span: 24,
            rule: [{ required: true, message: '请选择Exel', trigger: 'blur' }],
            mapdata: [{ label: '桩号', value: 'gtel' }],
          },
        ],
      }
    },
    methods: {
      change() {
        let formdata = this.$refs.zfrom.formdata
        if (formdata.gtelmc != this.frominputs[1].mapdata[0].label) {
          this.frominputs[0].defaultValue = formdata.gtelmc
          this.frominputs[1].mapdata = [
            { label: formdata.gtelmc, value: 'gtel' },
          ]
        }
        //
        console.log(formdata)
      },
      show() {
        this.dialogFormVisible = true
      },
      save() {
        this.$emit('save', this.$refs.zfrom.formdata.excel)
        this.close()
      },
      close() {
        this.dialogFormVisible = false
      },
    },
  }
</script>
